<template>
	<view class="container">
		<view class="example">
			<uni-forms ref="form" :model="rxalctz" label-width="100px" >
				<uni-forms-item label="病程（月）" name="hzbc">
					<uni-easyinput :disabled="isDisabled" v-model="rxalctz.hzbc" type="digit"  @change="autoSaven" placeholder="请输入病程（月）" />
				</uni-forms-item>
				<uni-forms-item label="首发症状" name="sfzz">
					<uni-easyinput :disabled="isDisabled" v-model="rxalctz.sfzz"  @change="autoSaven" placeholder="请输入首发症状" />
				</uni-forms-item>
				<uni-forms-item label="左右" name="wzzy">
					<uni-data-select
					      :disabled="isDisabled" v-model="rxalctz.wzzy"
					      :localdata="wzzyDict"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="方位（钟点）" name="fw">
					<uni-data-select
					      :disabled="isDisabled" v-model="rxalctz.fw"
					      :localdata="zdfwDict"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="距离乳头（cm）" name="jlrt">
					<uni-easyinput :disabled="isDisabled" v-model="rxalctz.jlrt" type="digit"  @change="autoSaven" placeholder="请输入距离乳头（cm）" />
				</uni-forms-item>
				<uni-forms-item label="大小（T）（cm）" name="dxCd">
					<uni-row class="demo-uni-row">
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.dxCd" type="digit"  @change="autoSaven" placeholder="请输入大小（T）（cm）" />
						</uni-col>
						<uni-col :span="2" class="wbkx">x</uni-col>
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.dxKd" type="digit"  @change="autoSaven" placeholder="请输入大小（T）（cm）" />
						</uni-col>
					</uni-row>
				</uni-forms-item>
				
				<uni-forms-item label="腋淋巴结肿大" name="ylbjzd">
					<uni-data-checkbox :disabled="isDisabled" v-model="rxalctz.ylbjzd" @change="sfywChange($event,'ylbjzdCKShow',['ylbjdxCd','ylbjdxKd'])" :localdata="dictYw" />
				</uni-forms-item>
				<uni-forms-item v-show="ylbjzdCKShow" label="大小（cm）" name="ylbjdxCd">
					<uni-row class="demo-uni-row">
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.ylbjdxCd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
						<uni-col :span="2" class="wbkx">x</uni-col>
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.ylbjdxKd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
					</uni-row>
				</uni-forms-item>
				
				<uni-forms-item label="锁骨上淋巴结肿大" name="sgslbjzd">
					<uni-data-checkbox :disabled="isDisabled" v-model="rxalctz.sgslbjzd" @change="sfywChange($event,'sgslbjzdCKShow',['sgslbjzdCd','sgslbjzdKd'])" :localdata="dictYw" />
				</uni-forms-item>
				<uni-forms-item v-show="sgslbjzdCKShow" label="大小（cm）" name="sgslbjzdCd">
					<uni-row class="demo-uni-row">
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.sgslbjzdCd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
						<uni-col :span="2" class="wbkx">x</uni-col>
						<uni-col :span="11">
							<uni-easyinput :disabled="isDisabled" v-model="rxalctz.sgslbjzdKd" type="digit"  @change="autoSaven" placeholder="请输入大小（cm）" />
						</uni-col>
					</uni-row>
				</uni-forms-item>
				
				<uni-forms-item label="远处转移" name="yczy">
					<uni-data-checkbox :disabled="isDisabled" v-model="rxalctz.yczy" @change="sfywChange($event,'zybwShow',['zybw'])" :localdata="dictYw" />
				</uni-forms-item>
				<uni-forms-item v-show="zybwShow" label="转移部位" name="zybw">
					<uni-easyinput :disabled="isDisabled" v-model="rxalctz.zybw"  @change="autoSaven" placeholder="请输入转移部位" />
				</uni-forms-item>
				
				<uni-forms-item label="转移确诊方式" name="zyqzfs">
					<uni-data-select
					      :disabled="isDisabled" v-model="rxalctz.zyqzfs"
					      :localdata="zyqzfsDict"></uni-data-select>
				</uni-forms-item>
				
				<uni-forms-item label="TNM分期" name="tnmfq">
					<uni-data-select
					      :disabled="isDisabled" v-model="rxalctz.tnmfq"
					      :localdata="tnmDict"></uni-data-select>
				</uni-forms-item>
				
				<uni-forms-item label="入院前治疗" name="ryqzl">
					<uni-data-select
					      :disabled="isDisabled" v-model="rxalctz.ryqzl"
					      :localdata="ryqzlDict"></uni-data-select>
				</uni-forms-item>
				
				<uni-forms-item label="备注" name="remark">
					<uni-easyinput type="textarea" autoHeight :disabled="isDisabled" v-model="rxalctz.remark"  @change="autoSaven" placeholder="请输入备注"/>
				</uni-forms-item>
				
				<button type="primary" :disabled="isDisabled" @click="submit">保存</button>
			</uni-forms>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
import { updateRxalctz,getDicts,sfkybjData } from "@/api/trms/trms"
import { getRxalctz } from "@/api/trms/query"
export default {
	data() {
		return {
			patientId: null,
			isDisabled: false,
			userId: null,
			// 表单数据
			rxalctz: {},
			wzzyDict: [],
			zdfwDict: [],
			zyqzfsDict: [],
			tnmDict: [],
			ryqzlDict: [],
			dictSf: [
				{
				  text: '是',
				  value: 1
				}, {
				  text: '否',
				  value: 0
				}
			],
			dictYw: [
				{
				  text: '有',
				  value: 1
				}, {
				  text: '无',
				  value: 0
				}
			],
			rules: {
				admissionNumber: {
				  rules: [{
					required: true,
					errorMessage: '住院号不能为空'
				  }]
				}
			},
			ylbjzdCKShow: false,
			sgslbjzdCKShow: false,
			zybwShow: false
		}
	},
	onLoad: function(option) {
		this.getDictZy();
		this.getDictZdfw();
		this.getDictZyqzfs();
		this.getDictTnm();
		this.getDictRyqzl();
		this.patientId = option.patientId;
		this.userId = option.userId;
		sfkybjData(this);
		console.log("进入乳腺癌临床特征页面后、参数：",this.patientId)
		if(this.patientId){
			// 查询详情
			this.getDataByPatientId();
		}
	},
	onReady() {
		this.$refs.form.setRules(this.rules)
	},
	methods: {
		/**
		 * 获取入院前治疗
		 */
		getDictRyqzl(){
			getDicts("trms_ryqzl").then(r => {
				this.ryqzlDict = this.dictFormat(r.data);
			});
		},
		/**
		 * 获取转移确诊方式
		 */
		getDictZyqzfs(){
			getDicts("trms_zyqzfs").then(r => {
				this.zyqzfsDict = this.dictFormat(r.data);
			});
		},
		/**
		 * 获取TNM
		 */
		getDictTnm(){
			getDicts("trms_tnm").then(r => {
				this.tnmDict = this.dictFormat(r.data);
			});
		},
		/**
		 * 获取位置左右
		 */
		getDictZy(){
			getDicts("trms_zy").then(r => {
				this.wzzyDict = this.dictFormat(r.data);
			})
		},
		/**
		 * 获取方位（钟点）
		 */
		getDictZdfw(){
			getDicts("trms_zdfw").then(r => {
				this.zdfwDict = this.dictFormat(r.data);
			})
		},
		/**
		 * 获取数据
		 */
		getDataByPatientId(){
			getRxalctz(this.patientId).then(response => {
			  this.rxalctz = response.data;
			  this.rxalctz.wzzy = this.rxalctz.wzzy + '';
			  this.rxalctz.fw = this.rxalctz.fw + '';
			  this.rxalctz.zyqzfs = this.rxalctz.zyqzfs + '';
			  this.rxalctz.tnmfq = this.rxalctz.tnmfq + '';
			  this.rxalctz.ryqzl = this.rxalctz.ryqzl + '';
			  this.initShow(response.data);
			});
		},
		/**
		 * 修改
		 */
		submit(){
			this.$refs.form.validate().then(res => {
				updateRxalctz(this.rxalctz).then(response => {
				  if(response.code == 200){
					  this.$modal.msgSuccess("修改成功");
					  this.backWork();
					  return;
				  }
				  this.$modal.msgError(response.msg);
				});
			})
		},
		autoSaven() {
			this.$refs.form.validate().then(res => {
				updateRxalctz(this.rxalctz).then(response => {
				  console.log("修改成功");
				});
			})
		},
		/**
		 * 回到工作页面
		 */
		backWork(){
			setTimeout(function (){
				uni.navigateBack({
					delta: 1
				});
			},500);
		},
		/**
		 * 给字典格式化成uniapp插件需要的格式
		 * @param {Object} list
		 */
		dictFormat(list){
			let newArr = [];
			if(!list){
				return newArr;
			}
			list.forEach(d=>{
				newArr.push({value: d.dictValue,text: d.dictLabel})
			})
			return newArr;
		},
		/**
		 * 隐藏显示
		 * @param {Object} e
		 * @param {Object} show
		 * @param {Object} valArr
		 */
		sfywChange(e,show,valArr){
			const val = e.detail.value;
			this[show] = val == 1;
			let that = this;
			if(Number(val) == 0 ){
				// 清理值
				valArr.forEach(v => {
					console.log(v)
					that.rxalctz[v] = null;
				})
			}
		},
		/**
		 * 初始化隐藏显示
		 */
		initShow(lctz){
			this.ylbjzdCKShow = lctz.ylbjzd == 1;
			this.sgslbjzdCKShow = lctz.sgslbjzd == 1;
			this.zybwShow = lctz.yczy == 1;
		}
	}
}
</script>


<style lang="scss">
  page {
    background-color: #ffffff;
  }

  .example {
    padding: 15px;
    background-color: #fff;
  }

  .segmented-control {
    margin-bottom: 15px;
  }

  .button-group {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
  }

  .form-item {
    display: flex;
    align-items: center;
    flex: 1;
  }

  .button {
    display: flex;
    align-items: center;
    height: 35px;
    line-height: 35px;
    margin-left: 10px;
  }
  
  .wbkx{
	  text-align: center;
	  margin-top: 10px;
  }
</style>
